package com.zc.im.controller;


import com.google.gson.Gson;
import com.zc.im.model.im.group.ZcImGroupMember;
import com.zc.im.service.im.group.ImGroupMemberService;
import com.zc.im.util.JsonUtils;
import com.zc.im.util.ResponseJson;
import com.zc.im.util.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 群组成员Controller
 * Created by wangcc on 2017/7/8.
 */
@Controller
@RequestMapping
public class ImGroupMemberController {

    @Autowired
    private ImGroupMemberService imGroupMemberService;
    private Logger logger = Logger.getLogger(ImGroupMemberController.class);


    /**
     * 查询群成员
     * @param groupmember
     * @return
     */
    @RequestMapping(value = "/getgroupmember",method = RequestMethod.POST)
    public ResponseJson selectGroupMember( String  groupmember ){
        ResponseJson responseJson = new ResponseJson();
        if (StringUtils.isEmpty( groupmember )) {
            return responseJson;
        }
        Gson gson = new Gson();
        ZcImGroupMember zcImGroupMemberModel = gson.fromJson(groupmember,ZcImGroupMember.class);
        List<ZcImGroupMember> listZcImGroupMemberModel = null;
        try {
            listZcImGroupMemberModel = imGroupMemberService.queryAllGroupMember( zcImGroupMemberModel );
        } catch (Exception  e) {
            logger.error(e.getMessage(),e);
        }
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("msgHistoryModels", JsonUtils.objToStr( listZcImGroupMemberModel ));
        responseJson.setDataMap(dataMap);
        return responseJson;

    }

}
